#include <bits/stdc++.h>
using namespace std;

const int R = 1e5 + 10;
int x1, y_1, x2, y2;
pair<int, int> p[R];
bool cmp(pair<int, int> a, pair<int, int> b)
{
	int dis1 = (a.first - x1) * (a.first - x1) + (a.second - y_1) * (a.second - y_1),
		dis2 = (b.first - x1) * (b.first - x1) + (b.second - y_1) * (b.second - y_1);
	if (dis1 < dis2)
	{
		return true;
	}
	return false;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, i;
	cin >> x1 >> y_1 >> x2 >> y2 >> n;
	p[0].first = x1, p[0].second = y_1;
	for (i = 1; i <= n; ++i)
	{
		cin >> p[i].first >> p[i].second;
	}
	sort(p + 1, p + n + 1, cmp);
	int ans = (x1 - p[n].first) * (x1 - p[n].first) + (y_1 - p[n].second) * (y_1 - p[n].second), dis1, dis2, max2 = 0;
	for (i = n; i >= 1; --i)
	{
		dis1 = (p[i - 1].first - x1) * (p[i - 1].first - x1) + (p[i - 1].second - y_1) * (p[i - 1].second - y_1);
		dis2 = (p[i].first - x2) * (p[i].first - x2) + (p[i].second - y2) * (p[i].second - y2);
		max2 = max(max2, dis2); // 2号需要的代价是i~n中距离最大的
		ans = min(ans, dis1 + max2);
	} // 第1~i-1由1号系统拦截，i~n由2号系统拦截
	cout << ans;
	return 0;
}
